package win.smartown.java.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by smartown on 2017/5/16.
 */
public class TerminalReader {

    public void tryRead() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入任意字符，输入'q'退出！");
        char c;
        while (true) {
            c = (char) bufferedReader.read();
            if ('q' == c) {
                System.out.println("已退出");
                break;
            }
            System.out.println(c);
        }
    }

    public void tryReadLine() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("请输入任意字符串，输入'quit'退出！");
        String string;
        while (true) {
            string = bufferedReader.readLine();
            if ("quit".equals(string)) {
                System.out.println("已退出");
                break;
            }
            System.out.println(string);
        }
    }

}
